package com.ruoyi.otc.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.otc.domain.Label;
import com.ruoyi.otc.service.ILabelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标签信息Controller
 * 
 * @author gjp
 * @date 2023-10-22
 */
@Controller
@RequestMapping("/otc/label")
public class LabelController extends BaseController
{
    private String prefix = "otc/label";

    @Autowired
    private ILabelService labelService;

    @RequiresPermissions("otc:label:view")
    @GetMapping()
    public String label()
    {
        return prefix + "/label";
    }

    /**
     * 查询标签信息列表
     */
    @RequiresPermissions("otc:label:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Label label)
    {
        startPage();
        List<Label> list = labelService.selectLabelList(label);
        return getDataTable(list);
    }

    /**
     * 导出标签信息列表
     */
    @RequiresPermissions("otc:label:export")
    @Log(title = "标签信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Label label)
    {
        List<Label> list = labelService.selectLabelList(label);
        ExcelUtil<Label> util = new ExcelUtil<Label>(Label.class);
        return util.exportExcel(list, "标签信息数据");
    }

    /**
     * 新增标签信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存标签信息
     */
    @RequiresPermissions("otc:label:add")
    @Log(title = "标签信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Label label)
    {
        return toAjax(labelService.insertLabel(label));
    }

    /**
     * 修改标签信息
     */
    @RequiresPermissions("otc:label:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Label label = labelService.selectLabelById(id);
        mmap.put("label", label);
        return prefix + "/edit";
    }

    /**
     * 修改保存标签信息
     */
    @RequiresPermissions("otc:label:edit")
    @Log(title = "标签信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Label label)
    {
        return toAjax(labelService.updateLabel(label));
    }

    /**
     * 删除标签信息
     */
    @RequiresPermissions("otc:label:remove")
    @Log(title = "标签信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(labelService.deleteLabelByIds(ids));
    }
}
